package com.yuzhi.fine.activity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.TextView;

import com.yuzhi.fine.R;
import com.yuzhi.fine.model.GanHuo;
import com.yuzhi.fine.ui.swipebacklayout.SwipeBackActivity;
import com.yuzhi.fine.ui.webview.LWebView;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by tiansj on 15/6/29.
 */
public class DetailActivity extends SwipeBackActivity {

    private static final String TAG = DetailActivity.class.getSimpleName();
    @Bind(R.id.btnBack)
    Button btnBack;
    @Bind(R.id.textHeadTitle)
    TextView textHeadTitle;
    @Bind(R.id.web)
    LWebView mLWebView;
    private GanHuo mGanHuo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail);
        ButterKnife.bind(this);
        initView();
    }

    @SuppressLint("SetJavaScriptEnabled")
    void initView() {
        mGanHuo = (GanHuo) getIntent().getSerializableExtra("ganHuo");
        textHeadTitle.setText(mGanHuo.getDesc());
        btnBack.setVisibility(View.VISIBLE);
        btnBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        mLWebView = (LWebView) findViewById(R.id.web);
        mLWebView.setProgressStyle(mLWebView.Circle);
        mLWebView.setBarHeight(8);
        mLWebView.setClickable(true);
        mLWebView.setUseWideViewPort(true);
        mLWebView.setSupportZoom(true);
        mLWebView.setBuiltInZoomControls(true);
        mLWebView.setJavaScriptEnabled(true);
        mLWebView.setCacheMode(WebSettings.LOAD_NO_CACHE);
        mLWebView.setWebViewClient(new WebViewClient() {
            //重写此方法，浏览器内部跳转
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                System.out.println("跳的URL =" + url);
                view.loadUrl(url);
                return true;
            }
        });
        Log.d(TAG, mGanHuo.getUrl());
        mLWebView.loadUrl(mGanHuo.getUrl());

    }

    @Override
    protected void onDestroy() {
        mLWebView.destroy();
        ButterKnife.unbind(this);
        super.onDestroy();
    }
}
